package com.bootdo.imgtext.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.imgtext.domain.DocitemDO;
import com.bootdo.imgtext.service.DocitemService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 单条检测结果
 * 
 * @author ke
 * @email 1992lcg@163.com
 * @date 2018-08-10 11:27:09
 */
 
@Controller
@RequestMapping("/imgtext/docitem")
public class DocitemController {
	@Autowired
	private DocitemService docitemService;
	
	@GetMapping()
	@RequiresPermissions("imgtext:docitem:docitem")
	String Docitem(){
	    return "imgtext/docitem/docitem";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("imgtext:docitem:docitem")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<DocitemDO> docitemList = docitemService.list(query);
		int total = docitemService.count(query);
		PageUtils pageUtils = new PageUtils(docitemList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("imgtext:docitem:add")
	String add(){
	    return "imgtext/docitem/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("imgtext:docitem:edit")
	String edit(@PathVariable("id") Integer id,Model model){
		DocitemDO docitem = docitemService.get(id);
		model.addAttribute("docitem", docitem);
	    return "imgtext/docitem/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("imgtext:docitem:add")
	public R save( DocitemDO docitem){
		if(docitemService.save(docitem)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("imgtext:docitem:edit")
	public R update( DocitemDO docitem){
		docitemService.update(docitem);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("imgtext:docitem:remove")
	public R remove( Integer id){
		if(docitemService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("imgtext:docitem:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] ids){
		docitemService.batchRemove(ids);
		return R.ok();
	}
	
}
